<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.google.appengine.api.datastore.DatastoreServiceFactory" %>
<%@ page import="com.google.appengine.api.datastore.DatastoreService" %>
<%@ page import="com.google.appengine.api.datastore.Query" %>
<%@ page import="com.google.appengine.api.datastore.Entity" %>
<%@ page import="com.google.appengine.api.datastore.FetchOptions" %>
<%@ page import="com.google.appengine.api.datastore.Key" %>
<%@ page import="com.google.appengine.api.datastore.KeyFactory" %>
<%@ page import="com.google.appengine.api.datastore.Query" %>
<%@ page import="com.google.appengine.api.datastore.Query.FilterOperator" %>

<% 
	DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
		Key accountKey = KeyFactory.createKey("AudioFiles", "mediaFiles");
		int rawByteSize;
		Query query = new Query("Audio", accountKey).
				addFilter("user", FilterOperator.EQUAL, (String)session.getAttribute("username")).
				addSort("mediaName", Query.SortDirection.ASCENDING).
				addFilter("contentType", FilterOperator.EQUAL, "audio");
		List<Entity> list = datastore.prepare(query).asList(FetchOptions.Builder.withLimit(20));

		%>
		<h2>Sort By Artist</h2>
		<a href="/audioGallery.jsp">All Artists</a><br />
		<%
		for (Entity artist: list) {
			%>
			<a href="/audioGallery.jsp?artist=<%= artist.getProperty("artist") %>"><%= artist.getProperty("artist") %></a><br/>
			<%
		}
		%>
		<br />
		<h2>Sort By Album</h2>
		<a href="/audioGallery.jsp">All Albums</a><br />
		<%
		for (Entity album: list) {
			%>
			<a href="/audioGallery.jsp?album=<%= album.getProperty("album") %>"><%= album.getProperty("album") %></a><br/>
			<%
		}
		%>
		<br />
		<h2>Sort By Genre</h2>
		<a href="/audioGallery.jsp">All Genres</a><br />
		<%
		for (Entity genre: list) {
			%>
			<a href="/audioGallery.jsp?genre=<%= genre.getProperty("genre") %>"><%= genre.getProperty("genre") %></a><br/>
			<%
		}
%>